Your code looks correct. It's just that the algorithm is not guaranteed to find the first excited state every time. The key thing you need to experiment with is the "Weight" parameter which is the penalty for psi1 and psi0 to have a non-zero overlap. I would start with a weight of 1.0 and experiment with other values if that doesn't work. Also start out on small systems where you know the answer. Finally, make sure the ground state is very well converged before trying to get the first excited state.
Even when you use this algorithm very carefully, it can sometimes miss excited states (it depends on how you initialize the MPS and how you optimize them). So you might get the ground state, first excited state, then the third excited state, and then the second excited state.
There is another approach to getting excited states with DMRG called "multiple targeting". We don't offer a black-box interface for that algorithm in ITensor right now but it would certainly be possible to implement and I think our Davidson code is set up to do it. That's something you could try to code yourself if the above method continues not to work.