If some error arises in regex.sub or others, we still need to remove the backup file. So maybe use a try/finally. This case should be tested by swapping out one of the interior functions to raise an error, and we should verify that the backup file still gets deleted.