Use event polling instead of blocking when outputting to a file.

This stops some ref tests on linux blocking while waiting for
user input events and never outputting the file.

Also mark vertical writing test as flaky on all platforms. Due
to unrelated timing reasons, this fails reliably on mac when glutin
is enabled. The related bug with details on the root cause is #3926.