Ah - you've got a quantum bug there (a bug that changes under observation/measurement). I suggest reverting to more primitive debugging techniques, i.e. adding "print" statements around the suspected buggy code. Those statements may fix the bug the same way using the debugger does, but at least you'll have removed the debugger from the equation.
Update
Never mind the above advice - your code is too straightforward to be causing the quantum bug. However, I suspect your problem is with using Net::LDAP asynchronously. Try setting "async" to zero - your ldap object may not be completely finished with everything it is attempting to do before you ask it to do something else. This is just a guess, mind you...