If a file starts with <!doctype html>, then the download has failed.
This should stop processing, and the script should check for existing files before processing each. This will make it resumable. The initial loop loading the list should also check for duplicates and re-save the file without duplicates if duplicates are found.