Fixes #6187 - Write library env destroy code in dynflow

**WORK IN PROGRESS. NOT READY FOR REVIEW.**