I don't know if it makes a difference, but every header should be followed by \r\n.
Not in Perl it shouldn't. \n and \r map to different values depending on platform. What you should have said was that "every header should be followed by \015\012". This is all documented in perldoc perlport.