Make `--out` to create parent directories

Fix #1389.
Merge pull request #1391 from yous/patch-out-parent-directories

Make `--out` to create parent directories