There is a fair bit of mathematics hidden behind this experiment. You'll also have seen that the car base didn't move up and down but rather moved along the track at the same height the whole time. This is because the square wheels followed the dips and rises of the curved water bottles exactly, making the axles of the car not move up and down vertically at all. The line that each edge of the square wheels were following is called a catenary curve.
As your square wheel moves along the curved track you'll notice that the sides of the square follow the curve of the water bottle without jamming into the bottles. This is the same issue engineers have to sort out when meshing gear teeth together.
The mathematics can be daunting for younger kids but great to follow through with high school math students. The Exploratorium has done a neat summary of the mathematics. Note that l is the side of the square wheels and d is the diameter of the water bottles.