LEGO Mindstorm NXT memorize line followed (LeJos)
I will preface this by saying that I'm just going to summarize what I suggest you do, as writing out the code step-by-step would take quite a while, and you writing the code will help improve your skills.  I recommend checking out the LeJOS API while I describe some of the classes, it is pretty easy to look them up there.

If you want to know the location of the robot, you need to use some sort of Pilot class.  To me, it sounds like you want to use the DifferentialPilot (of course, use the Pilot class that controls your robot, for instance, a triangle robot).  You create the DifferentialPilot with a wheel diameter, distance between the wheels, the Motor that is on the left, and the Motor that is on the right.

Create a Navigator, and give it the Pilot so that it can control the robot.  Next, create a Timer that will poll the position of the robot however often you want (maybe something like every second?).  I think you get the position from the Pilot.  Call addWaypoint() on the Navigator with the x and y position (which I think you can pull the pose from the Pilot).

Now, modify your line-following code so that it uses the Pilot's controls (travel(), rotate(), etc.).

When you have followed the line, you should have a list of Waypoints that you can use to navigate the same path, without using the line-following code.

You can then call followPath() on the Navigator, and the robot should follow the path.

Of course, it is important to make sure that your DifferentialPilot or whatever is as precise as it can be, so measure and refine the wheel diameter until you get really good accuracy, using whatever surface you are going to be using in the end.  If you have any questions about calibration, I would recommend a new question, but for now, I have a video here which covers it and shows the step-by-step process (hopefully this doesn't count as advertising, it is not intended to be any).

Hopefully I was clear, it can get a bit jumbled together after programming NXTs with LeJOS for a number of years!