Use the proper 'csv' library for the conversion to CSV

* still need the .encode("utf-8") for the empty case