Paul's exact words are :
λεγει γαρ η γραφη τω φαραω [TR][Stephens, Beza, Elzevir and Scrivener identical]
Literally (very literally, see EGNT or Biblehub) :
Speaks for the script (nominative, feminine, singular noun) to Pharoah (dative, masculine singular). Biblehub.
Paul begins his sentence by stating that something was spoken. It was originally spoken by God.
And the Lord said unto Moses - Rise up early in the morning, and stand before Pharaoh, and say unto him . . . . . [Ex 9:13]
What was spoken to Moses (not written down, but spoken) included a statement (also not written down) to Pharaoh.
Thus saith the LORD God of the Hebrews, Let my people go, that they may serve me . . . . .. . . And in very deed for this cause have I raised thee up, for to shew in thee my power; and that my name may be declared throughout all the earth. [Ex 9:13 and 16, KJV.]
God spoke those words to Moses. Then Moses spoke those words. And Pharaoh heard them.
Later, they were recorded.
That writing still speaks. It is still God's speech.
What God has uttered never becomes silent.
His words never fall to the ground.
They echo round the world to this day.
This is true of all scripture that is given by inspiration of God. It is his word. He utters it and it never becomes silent. It echoes to every generation to those who have ears to hear it.
That which was written, spoke to Pharaoh.
That is to say :
That which was (later) written spoke to Pharaoh (before it was written).