Saving Environment Variable Value and Response in a CSV File

So, my task is that I have to save environment variable value and response value in a csv file so the csv file will only contain these two values. Iam attaching the test script below for reference. One Approach that Iam trying to do is trying to retrieve the console messages/response and saving them in a csv file using Newman command and creating java script file in visual studio. I have tried multiple times but Iam unable to do the task. So if anyone knows how to do it kindly tell me. P.S I have already tried taking help from Chat GPT.

Plz Kindly help me.