Is there some conditional code immediately before the WITH CTE AS... part that expands to something wrong (like a SQL statement without semicolon) on the QlikView server (but does not in your Desktop)? Although a semicolon isn't strictly required in T-SQL up until SQL Server 2014, some SQL statements don't like to be glued together as that may lead to ambiguous code. Just an idea.
The best thing you can do is post the offending part of your script. Please do add the part before the WITH CTE AS line.