Writing statistics to file