Handle newlines more consistently when writing files