I don't see a db2 terminate
command in between changing from 1 instance to the other, so it would appear that the DB2 backend process may be confused about which instance it's supposed to be attached to.
Try executing db2 terminate
just before executing set DB2INSTANCE=myinst
.