Implemented graph writing to ouput file