Fixed a bug regarding CSV output.

This is the same CSV bug that has been fixed before. It should now correctly quote CSV output and escape existing quotes.

Closes #516