You have not really given us much to go on, but I'll make a couple of guesses:
1) you are using the on-board data EEPROM that your chip has
2) you are not clearing the EEADRH register when you try to write to the data EEPROM and/or not properly handling the EEPGD bit
3) therefore when perform the write operation, you are actually writing to the program flash and not the data EEPROM, thereby corrupting the program
4) worse still, as the flash write occurs in blocks of 8 words, the values in memory above the one you are trying to write will also be written to the flash memory
I know you are dealing with a stepper motor and those things are notorious for putting noise onto supply and data lines, but the chances that the noise could emulate the programming signal sequence is vanishingly small.
The bottom line is that the flash memory is unlikely to be changing by itself and therefore you need to look at your program for the actual cause and, because of the similarity of the way you write to flash and data I an guessing that the problem lies there.
Susan