properly encode new lines and quotes
write synchronous to stdout