Change file handle to binary mode
open (FILEHANDLE, ">data.txt") or die ("Cannot open data.txt"); binmode FILEHANDLE; print FILEHANDLE "Hello\nthere!"; close (FILEHANDLE);