To add to Fletch's (rather unnecessarily vociferous) correction, the right way to do it is to pass both arguments to header at the same time.
in reply to Re^3: Changing the content type
in thread Changing the content type
If you're using a framework like CGI::Application, there are utility methods for keeping track of multiple headers and outputting them exactly once, so you don't have to keep track of lots of print statements and won't accidentally print two sets of headers.
print $q->header(-type => 'text/xml',
-attachment => 'filename.xml');