fix race condition in screenshot save.

We need to wait for the disk write to finish before continuing as
otherwise it is possible that we will try to read a partially written
file.