You may want to read up further on Fermat's principle.
Your response is a little bit ill-formed because Fermat's principle is about the time to travel between two points. You assert that light is not "taking the shorter path", but in doing so you are changing the destination point or else leaving it undefined. Instead, pick a start point, pick an end point, and see how light travels between those two points, with respect to your cube of glass.
From the perspective of their own frame, photons don't travel. They are everywhere along their path at once. From our perspective, a photon goes through A first, then B. From the photon's perspective, that is not how it is.
So the concept of a photon 'picking' a destination point, or not, is mired in an assumption that isn't true (that there would even be anything to pick).
Your response is a little bit ill-formed because Fermat's principle is about the time to travel between two points. You assert that light is not "taking the shorter path", but in doing so you are changing the destination point or else leaving it undefined. Instead, pick a start point, pick an end point, and see how light travels between those two points, with respect to your cube of glass.