I think gumball's idea should work. It's just using a sprite to make a line, but that part can be dealt with later.
The first task would be to get the motion working in tight spaces like that, and not get snagged at intersections. I think a pacman tutorial would probably help with this, since the motion is similar. Aka. Motion in tight corridors.
To keep the object from crossing it's own path is the next problem. Basically you could have a square at each intersection and make them solid as needed.
To do this you can use an array as a list of corners. The list starts with just the starting corner in it.
When the distance between the player and the last corner in the list gets big enough, then the last corner the player overlapped is added to the list. The idea here is if the distance is bigger than the distance between corners then the player passed a corner.
To do the backtracking, the distance between the player and the 2nd from last corner of the list is compared, and if it's less than a edge length, remove the last corner from the list.
So now that gives you a list of corners. If you keep all of them but the last one solid, then you can keep the player from crossing it's path.
Finally you can take that list and make lines between them all and from the last to the player. You could either use gumball's idea or the canvas plugin I suppose.
Anyways that's the idea at least, I was going to try to type out events but it seemed more understandable describing it. I haven't tested the idea yet but it should at least be a start.