Write files in "binary" mode.

On unix there is no difference between binary and normal mode. On
windows normal mode converts all line endings to windows style line
endings while binary mode preserves the line endings as they were
written (in this case '\n')

The javascript for highlighting kanji relies on line endings to be '\n'.