Fixed Double fclose of temp file