It's because you're trying to run it across databases. The CTE created in the database you're in, not the database you're running against.
I'm unsure of how to resolve that. I'll have to do a bit of research.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning