Great script, but I found a problem.
If the ANSI setting CONCAT_NULL_YIELDS_NULL is ON, then I received some records with a NULL value. When I changed the setting to OFF, then the resulting statement was incomplete; i.e., the GRANT statement was missing.
Example:
--ARS_PROD DELETE ON AREA TO Developer GO
Notice the 2 spaces between the database name and the permission, with no GRANT statement in between.