Prevent corrupted image files.

Write captured image to a temporary file to prevent other processes
reading from getting an incomplete/corrupted image.