Call function only once in Coroutine

Hey, I am pretty new to Unity and all, I’ve been playing around with it in school for last 2-3 weeks.
I am creating a game that spawns enemies and counts your score for every enemy killed. I am using a coroutine to spawn the enemies, but now I wanted to change the amount of enemies spawned per second, after you killed a few of them. Problem is if I try to use the line "
ScoreManager testScore = GameObject.Find(“Scores”).GetComponent(); "
it calls it infinite amount of times and it eats up my ram until I go into Task Manager and turn it off.
So the question I have is how can I call the ScoreManager line only once?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SpawnManager : MonoBehaviour
{
    [SerializeField]
    private GameObject _enemyPrefab;
    void Start()
   
    {
        StartCoroutine(SpawnRoutine());
    }

   
    private IEnumerator SpawnRoutine()
    {
        while (true)
        {
            float randomX = Random.Range(-21f, 21f);
            Instantiate(_enemyPrefab, new Vector3(randomX, 15f, 0),
                Quaternion.identity);
            ScoreManager testScore = GameObject.Find("Scores").GetComponent<ScoreManager>();
            if ((testScore.score > 0) && (testScore.score < 10))
            {
            yield return new WaitForSeconds(1.5f);
            }
            if ((testScore.score > 10) && (testScore.score < 20))
            {
            yield return new WaitForSeconds(1f);
            }

Find your object/component once and cache it from the Start method:

private ScoreManager _testScore;

void Start()
{
  _testScore = GameObject.Find("Scores").GetComponent<ScoreManager>();
}

Or even better, ditch GameObject.Find and just expose _testScore in the inspector, then drag/drop the reference to it.

You probably have a case of an infinite loop.
It seems you do not have a yield return instruction if your test score is 0, 10, or 20 and above. You need to make sure that a yield return instruction is executed in every single iteration of the loop.