PIC18F2550 Loop Counter Overwritten by sprintf
Your problem is this line:

char output[20];


You are allocating 20 characters for the buffer to hold your string, then calling sprintf() to fill it.

However your format string is too long, even before the decimal value is included.  Remembering that the last array element will always need to be \x00 (a NUL character) you have 19 characters to use for your message.

Count the number of characters in this string:


  Sensor %d is currently off \r\n


There are 29 characters (assuming a two digit number).  This results in a buffer overflow, which will start to clobber other variables and may cause your program to operate in an unexpected manner.  It is one common type of security issue in C.

Increase the size of your buffer so it is large enough to contain:


all of the fixed letters from your message.
the largest number the variable i will ever hold.
the trailing \r\n.
the terminating NUL byte.