fix newline handling on write