added writing to file every 20min and every 1min