Never use scanf if you can help it. It will stop at the first character it considers invalid and leave it to be read next time -- so next time you scanf to read a line it instantly fails.
If you want to input individual lines, scanf is overkill anyway -- use the purpose-built line reading function, fgets(buffer, size, file);
It adds a NULL to the end like most string functions. It also leaves in the newline, just to warn you.
And if you want to use scanf to extract parts of a line, you can do sscanf(buffer, "command string", &var1, &var2, ...)
to scan the string you just got with fgets, no worries about scanf leaving junk in the buffer that way.
There's also a printf function which writes to a buffer, sprintf(buffer, "commandstring", arg, arg, ...);
which you can use to conveniently format data before feeding it into write() if you want.
Your readline function makes an assumption, namely, that the stream contains NULLs. Since you haven't posted most of your code, I have no idea at all if these assumptions are true everywhere. But I'm guessing they're not.
write() is not a stdio function, it's a raw system call -- it doesn't add anything for you, it sends bytes as given without question. So write(fd, "abcd", strlen("abcd")) sends four bytes with no NULL terminator. strlen()+1 will send the NULL assuming there is one.
You do have the right idea in using a terminator, since a write on one end might not all arrive in one read on the other.