Added the overwrite logic for existing files.