Make stdout flush properly

If one redirected stdout to a log, the output wouldn't show. This explicitly flushes after each line of output, which will write it immediately.