generate file with dos or unix newlines, optional newline at end of file