Simple, cheap and robust light gate for use in schools
While your "wants" are commendable, you may have to make compromises for the following reasons:


Your optical system must work in a classroom, in competition with
room lights.
Ideally, your light-emitter (LED) will be visible so
that it can be well-aimed.
While long range might be a goal,
you'd want many such optical gates to work in the same room without
interference from others.
Using a PC's sound input limits you to 20 - 20kHz.


Wouter van Ooijen has a suggestion that meets some of your criteria. A very simple microcontroller can drive your light-emitting diode at any frequency you want. Some LEDs are packaged with molded-in lens that limits directivity while increasing range. A battery is required.
The optical receiver is more difficult. A great many infra-red optical receivers are available for use as TV remote (or any appliance) receivers. These are universally limited to infra-red wavelengths, forcing you to use an infra-red LED that cannot be seen for aiming. These are three-pin receivers that require very little else than a battery and interface cable. It is possible that these can provide a signal to a PC's microphone input, detectable by Audacity. However, these chips are internally complex, and many will yield spurious outputs for two conditions:


A sustained period of no signal
A sustained period of full signal



These chips are designed to detect short bursts of signal such as those key codes transmitted by a TV remote. They detect the tone-burst modulation, and do not provide the carrier:

There are a very few versions of optical receivers that have simplified internal signal processing. Instead of actually detecting tone bursts, the photodetector signal is provided as output. Rather than detecting a specific frequency (usually found somewhere in the band between 30 kHz. - 60 kHz.) as TV remote receivers do, output frequencies from 20 kHz. - 60 kHz. are provided directly. Since 20 kHz. is acceptable to a PC's sound card input range, this type of receiver could provide a signal quite acceptable to a microphone, or line-in input. And Audacity could more easily recognize a 20 kHz. signal than the pulse edges provided by the more complex TV remote receivers. Audacity must now determine when the 20 kHz. is visible, and when it is not (this function is internal to the more complex receiver).