How and where do you access the left_word and right_word Var elements? If you need to access them in a different trial than they are set, you need to make them global.
Also, are you sure that there’s no standing space character before or after AB in your cell values?
newVar('left_word',(row.Naming_Order == 'AB' ? row.A_set_image : row.B_set_image)), newVar('right_word',(row.Naming_Order == 'AB' ? row.B_set_image : row.A_set_image)),