Add auto-mkdir -p before file-write.

Oh lawrd why didn't I use this before?