write-object can retain head of collections
If serializing a large data structure, the write-object function will retain head references, causing memory pressure.
The problem code looks to me like a typo:
calling seq on the parameter of the function, rather than the loop variable. That keeps the parameter in-scope during the recursion.