fail fast if cannot write file; simplify to_dir calc