Issue #18945: Add tests for tempfile name collision handling.

Patch by Vlad Shcherbina