To answer my own question, I fixed the input to write() the same way as I had done with $temppath (i.e. s/\\/\\\\/g) and things appear to work correctly now.
Everthing except for what appears to be some disrespect for case-sensitivity inside the archive... Dang; I just want to go home!