Refactor about output of newlines

For example

* write('foobar\n'). => writeln('foobar').
* write('\n'). => nl.