LPS-39794 Insecure temporary file creation

Tomas, can you help me review this before I send it to Brian. Thanks.