I have determined that Python is malforming the XML with DOS format inputs. The problem only appears in the XML output and not by comparing variables inputs.
The script functions enough to display the destination number in the GUI, but is not sane.
Direct command line input to the Python script does not cause the issue.
The forward list is created by other people if someone wants to know why a DOS text file is used for input. We will convert the file to Unix before running the script. We have also recently migrated to an E.164 dial plan introducing '\' to directory numbers which may contribute to the problem.
Confusing problem as the script did not outright fail with bad input.
Issue is resolved.