in reply to Displaying carriage returns

You need to tell the browser what sort of content it should be displaying.

To display as plaintext:

print header('text/plain');
To use whatever method the browser defaults to for xml:
print header('text/xml');
Personally I find the CGI header options limiting and tend to print them manually, e.g.:
print "Content-type: text/xml\n"; print "Content-Disposition: inline; filename=directory.xml\n\n";
Note that the initial output is treated as headers that define what is to come, which is terminated by two '\n'.

The reason for including the Content-Disposition header in this case is to provide an extra hint to browsers that care about file extensions, like IE.