in reply to CSV_XS issue
It's a bit weird that this is not the default, but comparing your code with the synopsis section of Text::CSV_XS shows this one line:
$csv->eol ("\r\n"); [download]
As soon as you add that, you'll get separated lines.