Buffer output in order to reduce number of syscalls