It seems to me like your code loops over all the possible flask values and checks all of them without stopping if it actually finds one. Therefore the flask value keeps getting overwritten and the answer you get eventually is the value for the last flask in your list.
You could try to modify your loop like this:
Lua Code:
for i = 1, #flasks do
flask = UnitBuff("player", flasks[i])
if flask then
break
end
end