If the number of columns is unknown, I would use the DynamicCrossTab approach instead of PIVOT.
Please see the two related articles referenced in my signature.
Since you most probably need to use Dynamic SQL, you cannot use a normal temp table (since it would be out of scope). There are two options I can think of:
1) create a global temp table in the sproc that calls the dynamic SQL and insert into that global temp table (use INSERT INTO ##GlobalTempTable SELECT... inside the dynamic SQL part) or
2) create a permanent table and insert into that table (you should consider concurrent inserts, so a unique sprocID column could be used to identify what values belong to a specific sproc.