It uses a temporary file in the same directory as the given path. This ensures that the temporary file resides on the same filesystem.
The temporary file will then be atomically moved to the target location: On POSIX, it will use 'rename' if files should be overwritten, otherwise a combination of 'link' and 'unlink'.