Electromagnet is acting perpetual... why?
The soft iron indeed got magnetized. Your closed soft iron loop has a flux running in it as soon you magnetized it and connected with that is a mechanical force to minimize the magnetic resistance in the loop. That's why the bar is stuck to the U.

Removing the bar from the U inserts an air gap, which has a large magnetic resistance and will dissolve all the flux previously running in the core. That's why you cannot get the bar stuck again.