adds newline in file writing and file closing