You probably need to go one or two steps further on the motor to ensure the flag is in the opto interrupter properly. this is the standard way that any motor finds its home position (like in a floppy drive seek mechanism). If this is not acceptable to you, then arrange the opto to be slightly further out. Another thing that is often done is once the opto senses the flag, then the motor is stepped to a given phase. This allows things to move slightly with temperature around the opto flag and its mountings, and only requires temperature compensation on a minimal number of close tolerance components.