Comparator Undesired Behavior
As others pointed out, this chip requires the input voltages be at least 1.5 or 2 V below the positive rail, and you don't seem to be following this restriction.

In comments you asked, 


  Why? Is there some kind of rule I should know about comparators? Why exactly 2V less than Vcc? 


Because the datasheet says so:



The limit is 1.5 V below Vcc at 25 C (as shown above) or -2 V over the full operating temperature range (shown in the next table in the datasheet).

If your next question is, "But, really, why?", have a look at the schematic in the datasheet:



If the input voltages get too close to the positive rails, the current sources shown will go out of regulation, so the circuit will not work as it does when biased properly.