Fix: we need to mkdirs before writing