A big issue with your sample is the redirection operator '>' - This will always overwrite the data in test.txt with the new data being entered. Use '>>' to append the output to the end of the file without deleting the information that is already in the file.
Instead of fixing your batch script, this PowerShell one-liner will give you the same result with much less effort.
While($true){Get-WmiObject win32_processor | Select-Object @{L="Date";E={Get-Date}},LoadPercentage,SystemName | Export-Csv -NoTypeInformation -Append CPU.csv; Start-Sleep -Seconds 5}
You can even target a remote computer with:
Get-WmiObject -ComputerName <
computer>
Sorry for not answering your specific question. I hope you will find what I have provided to be useful.