in reply to Output to a >CSV file

I'm (possibly mis-)interpreting your question as being related to HTML.

Your code shows that you are currently sending only TEXT output:
print "Content-type: text/plain\n\n" ;

If you want other outputs available, you will need to change to multipart HTML output, and add CSV or Excel content.

See RFC 4180.

                "From there to here, from here to there, funny things are everywhere." -- Dr. Seuss