This tuning loop picked k by the best TEST score — it just spent the test set on a decision, so the 85% it reports is quietly inflated by selection. Knobs get chosen on the validation scores; the test set is opened once, after choosing. Fix the selection line and accept the lower, uninflated number.
The break is on line 5 — but read the whole snippet first.