Writing files inside a dune test

If I want to depend on some files in a dune test, I can put (inline_tests (deps (source_tree data))) in my dune file and then anything in the data/ subdirectory gets copied into the build directory, and I can access it within tests using an ordinary relative path.

What if I want to generate some files and add them to data/ from within my test?

(Naturally I don’t want to do this every time! The goal is to have something like VCR where I can record an HTTP interaction the first time I run the test and then just read it out of the file subsequently.)