[SPARK-4597] Use proper exception and reset variable

`File.exists()` and `File.mkdirs()` only throw `SecurityException` instead of `IOException`. Then, when an exception is thrown, `dir` should be reset too.
It looks like these two methods can't throw `IOException` after all, is that the gist of it? `mkdirs` just returns `false` if it fails, hm. https://docs.oracle.com/javase/7/docs/api/java/io/File.html#mkdirs()

`dir = null` is a good bug fix. I might have changed this to not even assign `dir` and hold the new `File` in a temp variable until the checks succeeded. This looks equivalent though.