A driver in Florida was ticketed for flashing his headlights at oncoming traffic to warn of the nearby police officer. The driver fought the ticket and successfully argued that his conduct was "free speech" as protected by the First Amendment. As a result, Florida enacted a new law clarifying the fact that flashing high beams to alert other drivers is legal in the state. A current lawsuit in Missouri is claiming the same defense.
Pennsylvania*
In Pennsylvania, the issue is not 100% clear. The Pennsylvania Supreme Court ruled, in 1999, that Pennsylvania law does not allow police officers to ticket a driver who flashes their high beams to alert other drivers during the day.
However, no case or law directly addresses the issue of flashing high beams at night. The closest answer is to look to Pennsylvania's general high beam law:
"Whenever the driver of a vehicle approaches an oncoming vehicle within 500 feet, the driver shall use the low beam of light." 75 Pa. C.S.A. Sec. 4306
New Jersey*
In New Jersey, the law is very clear. In 1999 the Superior Court - Appellate division held that: a motorist may not be convicted of misusing her headlights to warn oncoming motorists of radar.
Overall, drivers should always exercise caution with their high beams. Pennsylvania drivers should keep in mind the high beam restriction when a vehicle is approaching in the opposite direction. New Jersey drivers have more leeway, but should always use a prudent approach. While driving through other states, be sure to keep in mind that their state laws may be different than those you are used to in Pennsylvania and New Jersey.
* This analysis takes the law as it stands on November 8, 2013. Keep in mind that laws can change.