Writing results automatically to file