Making --write-masked respect output dir.

Closes #317.

cc @metasoarous