Fix issues with editing CIB when using an external $EDITOR

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