ok I have two ways of explaining this.
1. time isn't cause and effect. it's just there. twilight knew because twilight told her where to go. it's as simple as that. how did twilight know in the first place? because twilight told her.
2. twilight said good spells are in canterlot. she wasn't looking for the back time spell. she was looking for a high level time spell. "by my calculations, the spell room (she doesn't say starswirl) should be around here somewhere." pinkie says "did you try that place over there? the starswirl the bearded area?" twilight looks and goes duh. she doesn't go there becaus twilight told her. she goes there because it's a big locked up room and assumes the spell she needs (not the time back spell) will be in there. so yes, she learns what to tell herself later and she didn't go there because of that information either.
The first explanation makes sense if we consider time to be a constant, singular line like in Slaughterhouse Five. You can travel forward and backward in time all you want, but you can't influence events because they've already happened that way, so it really doesn't matter where anything originates from, so long as it stays linear.