PORTx and LATx are not commands, they are registers (basically RAM location in the PIC).

Because of the way the PIC works internally (using a read-modify-write cycle) and depending on what the output pins are driving you can get the problem you had. Writing to the port latch (LATx) instead of directly to the port (PORTx) avoids the problem because the read-operation of the read-modify-write cycle is then performed agains the port latch instead of against the actual output pins.