This has happened to me several times. My problem was this:
BDM software will set the oscillator-trim value to make the CPU bus-clock a standard value (say, 10.0 MHz.) Your code, too, must set this value: Somewhere near the beginning you will need something like this:
lda $FFAF ; get BDM's calculated value from Flash
sta ICSTRM ; correct oscillator with it
Wade