write_images creates necessary directories