Escape filename to avoid problems with spaces
Use a scratch buffer instead of a temporary file