Add ability to write out CSV files

We need this to solve #165.