A similar solution already exists: APTonCD. It can repackage all installed programs, or individual programs; taking care of package dependencies as well. But it's method is fraught with one bug: it can't handle multiple levels of dependencies. I'm afraid it too uses the same logic for dependency resolving as yours. Plus, common dependencies: a dependency or an earlier package, is also a dependency of the current package, so it won't be downloaded(and packaged) again.
-- Regards, Chhatoi Pritam Baral -- LUG@IITD - http://lug-iitd.org/Footer
