I didn't write it, but thus far copying an environment has always been a pain in SQL
Jeff Jordan has written a handy stored proc that scripts out the environment and folders.
http://www.sqlservercentral.com/articles/Integration+Services+(SSIS)/135173/