Use fputcsv to write proper CSV data

Hi

PHP provides a native function to write CSV data, so I changed the code to use it.
Test cases were wrong btw so I changed them too.

Eric