Write data to file

Hi, welcome to the forum.

Because of the highly concurrent and potentially distributed nature of k6, it would be difficult to support writing to local disk like fs.write().

Instead you could use some type of distributed storage for this, like Redis or S3. There are a couple of Redis extensions for k6 that could help you with this, otherwise any system like S3 that exposes an HTTP API could be used. Though keep in mind that this will potentially impact performance of your test, and in the case of HTTP services would also skew your end-of-test summary results. You can avoid the metric skew by not depending on the summary and filtering these requests using tags in whatever output system you use.

You could also write a new k6 extension that stores files on the local filesystem, just be aware that this likely won’t be supported in k6 Cloud and would only work for your local single-instance tests.