When jumi (joomla plugin for PHP) compiles your code for some reason it removes all backslashes from your code. Such that something like $csv_output .= "\n"; becomes $csv_output .= "n";
Very annoying bug!
Use PHP_EOL instead to get the result you were after.