Fix writing to file.
Merge pull request #2 from jstoneham/fix-newline-handling

Fix writing to file.