Ok... this presented a challenge in obscure batch file scripting (something I haven't had to do in years!
If I understand your stated objective correctly, you want to create a secondary file that contains the literal output of %testvariable%
To do this the command would be:
echo %%testvariable%% >>test.bat
Hope this helps!