changed write_lines to use newline patterns