Hacky writing stats file, does not handle pre-emptions properly