test: add test_write_lines helper API and implementation as suggested by Junio. Signed-off-by: Michael S. Tsirkin <mst@redhat.com>