Ocamlbuild: make log printing code tail-recursive

When executing a command, ocamlbuild keeps the complete output in memory before writing to a log file.
The writing code is not tail-recursive, outputing too many lines can cause ocamlbuild to fail with "Exception Stack Overflow" message.

The proposed patch fix this (the output is still kept in memory).