It is very easy to create a csv file using PHP. All you need to do is create a two dimensional array of data and call fputcsv() function.

$aa = array( array ('a', 'b'), array('1 ', '2'));
$fh = fopen('file.csv', 'w');
foreach ($aa as $a) { 
   fputcsv($fh); 
}
fclose($fp);

This script create nice csv files even in you have quotes in the file.

Make sure your script has sufficient directory permission to create the file and populate it.