Print --http-debug logs into file & print all api responses in a file

You cannot open a file and write to it from inside of a k6 script, but you can redirect the k6 stderr output to a file like this:

k6 run --logformat=raw --http-debug=full github.com/loadimpact/k6/samples/http_get.js 2> http_debug.txt

Alternatively, you can find other approaches to debugging HTTP requests in Dump all outgoing requests in json?, including using console.warn() and such, though as you can see from that thread, there are caveats.