fix to write function, adding newlines.