It works fine when there is only one instance, but blows up when running tests in multiple threads: it seems that they get the same value from this lazy_static, and at least one of the tests is trying to use this file while it is locked by another test, therefore crashing. I feel like there should be another way to create them, but I'm not sure how to approach it.
If you don't want to create a temporary file for each test, using thread-local storage is a solution. thead_local macro from std can be used to create a TLS variable but because it has to be accessed in a closure as in doc, you may have to change your code a bit.