I thought this was going to be a cool script to try but cannot get the BCP commands it generates to work. I checked the MS docs and I don't see the problem. I tried tweaking the quotes, single instead of double, adding quotes elsewhere, etc.
Here's what one of output lines looks like in my SQL Server 2014 instance:
bcp "SELECT * FROM [AdventureWorksDW2008R2].[dbo].[DimAccount]" queryout c:\databases\DimAccount.csv -c -t, -T -S RCERGOL-TP