It's not clear why XML::Parser is segfaulting if no calls are being made to it by that code. Segfaults usually indicate serious problems with external libraries, and aren't usually thrown by (stable) versions of perl unless it invokes them. I'm afraid diagnosis of this problem requires looking at more than just the code.
One possiblity that pops to my mind is that your version of XML::Parser was compiled with a particular version of the expat C libraries, and that the version of expat installed on your system is a different one.
If not P, what? Q maybe?