Fix issues with editing CIB when using an external $EDITOR

Two bugs fixed:
 - a temp file write needs to be flushed first before being opened it with an external editor
 - catch traceback when an invalid $EDITOR is specified