Here's one way to save your image viewer's process id (PID) and close it later:
z" qiv Doc/bertie.jpg & echo $! > qiv.pid" >system
As mentioned in the previous answer, the $! environment variable gives the PID of the most recent process. The PID is captured to the file qiv.pid.
Then use the command pkill to kill the process with the captured PID:
z" pkill -F qiv.pid" >system