You made sure your output isn't buffered (
$|=1;), so that means the it must be one of the other programs that is buffering its output.
ssh,
tail and/or
grep realize they are connected to a pipe and buffer their output as a result. You'll need to convince the offender(s) that they are connected to a terminal via some command line option or by using a pseudo tty (ptty).
For my versions of tail, grep and ssh, I found that
- tail -f doesn't buffer its output.
- grep buffers its output unless it's output is connected to a terminal or --line-buffered is provided.
- ssh doesn't buffer its output.
Adding --line-buffered to grep should do the trick.
Update: Added "For my version" on.