Added replace to strip newlines before writing to file