write stats to a file in the end