More robust replay file creation
Merge pull request #3161 from ScottNZ/replay

More robust replay file creation