File/SysTempFileFactory.php
public function createFile($content = null, $extension = 'tmp')
    {
        $filename = $this->generateFilename($extension);
        if (file_exists($filename)) {
            throw FileAlreadyExistsException::create($filename);
        }

        $tempFile = new \SplFileObject($filename, 'x+');
        if ($content !== null) {
            $tempFile->fwrite($content);
            $tempFile->fflush();
        }

        return $tempFile;
    }
public function createFile($content = null, $extension = 'tmp')
    {
        $filename = $this->generateFilename($extension);
        if (file_exists($filename)) {
            throw FileAlreadyExistsException::create($filename);
        }

        $tempFile = new \SplFileObject($filename, 'x+');
        if ($content !== null) {
            $tempFile->fwrite($content);
            $tempFile->fflush();
        }

        return $tempFile;
    }
Essentially, an "improved" tempnam().

As compared to the core tempnam, this version allows you to add a file
extension, returns an SplFileObject and has a short hand for priming it
with some content. If content is written, the file is not rewound before
returning.

@param  string|null    $content
@param  string         $extension
@return \SplFileObject