writing graph to cvs file

Thanks to Maddy.