tests: add write_script helper function