Added writing to csv