write logic, writing results to file