write graph to file