Fixed writing stats to file