added write of averages to file