Strange I2C Behaviour on PIC and some doubts
Try adding: while(1){} to the end to keep your program from resetting.

Unlike running a PC application, microcontrollers have nowhere to exit to from main(). Generally you need to have an infinite loop or the processor or code will reset and get executed over and over.

For more complete explainations, see:

Who receives the value returned by main()?

or:

What happens when an embedded program finishes?