[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.
Yes. The only exception they would throw is `SecurityException`.