You will never completely get rid of latency.
Latency is the time it takes for a signal to be processed from the input of your soundcard, through the electronics and sent to the output.
pre-recorded tracks are sitting on your hard drive, when you hit record audio data is cached and processed through your outputs.
The signal you are recording is still at the input.
The easiest way to deal with latency is with a multibus mixer, so you can monitor your signal before it goes through your soundcard. And you can listen to the prerecorded material on another bus, and be perfectly in sync.
All recording systems have latency, analog tape machines deal with it by the placement of the record and playback heads.