When using non-interactively, most standard commands, include
grep, buffer the output, meaning it does not write data immediately to
stdout. It collects large amount of data (depend on OS, in Linux, often 4096 bytes) before writing.
In your command,
grep's output is piped to
sed command, so
grep buffer its output.
--line-buffered option causing
grep using line buffer, meaning writing output each time it saw a newline, instead of waiting to reach 4096 bytes by default. But in this case, you don't need
grep at all, just use
tail -f <file> | sed '/string/s/stuff//g' >> output.txt
With command that does not have option to modify buffer, you can use GNU coreutils stdbuf
tail -f <file> | stdbuf -oL fgrep "string" | sed 's/stuff//g' >> output.txt
to turn on line buffering or using
-o0 to disable buffer.