I checked memory and its appears the script is just slightly over 11Mbs when it dies (which for my machine is very small). I am actually surprised to see the usage so low. Similar scripts that I've written for the same problem often exceed 40Mbs.
I can't shorted the code and get the segmentation violation but I've found a set of data (and circumstances) that causes the crash to occur about 10 mins.