added code to write results to file