CSV files are somewhat more complex than they might initially appear. I reccomend using Text::CSV to generate your file instead of trying to do it directly.
Text::CSV will fail if you have any newlines embedded in your data. I strongly recommend using Text::CSV_XS which not only handles the newlines but is also much faster.