I suspect overwriting an open file will cause failures on Windows.
Using `mkdtemp` would seem a more portable options.