The problem went away when I removed the "end" statement. It looks to me that having MCLR as an input pin and then declaring it as an output and then writing "end" in the mainloop causes the MCLR pin to be pulled low when it is powered up, thereby ignoring MCLR when trying to program it. That is a curious state of affairs. I wonder if there is a way around this?
Bookmarks