Fixed potential race issue with temporary directory in test