Allah already knew what each servant would freely choose if granted choice. Allah wrote in accordance with that knowledge, and the servant performs the action.
The servant's act is performed through their choice. Allah's foreknowledge does not negate the fact of that choice, for His knowledge encompasses the action before it occurs.