Improve exception handling around file writing

Created function for making directories. Added custom error
raised when overwriting is attempted.