Use a real temporary directory if the __DIR__ path is not writable

Hi, we have notices that errors are thrown when the source directory is not writable. We propose to use a real temp dir provided by the system when the default folder is not writable.