print to file and flush