write out data to csv