This question is fairly easily answered. It is certainly true that in the year AD 30, John was an “unschooled, ordinary man.” (Acts 4:13). However, the book of John was written, at the earliest in the late 70s AD. Scholars normally place the date of writing some time in the 80s AD. Some even move it into the 90s. John was perhaps about 20 years old when he was a disciple of Jesus. By the time he wrote the book he was in his seventies or perhaps even in his eighties. In the intervening fifty years, John could easily have learned, not only how to speak Greek, but also how to read and write Greek. In fact, by some time in the 70s he was living in Ephesus as an elder of the church there, overseeing the churches in Asia. The language in Ephesus was Greek. John had been living in a Greek-speaking territory for years before writing his gospel. This (that he was an elder in Asia) explains his letters to these churches in the book of Revelation. John devoted himself to the study of and teaching of the Scripture. The Bible of the early church was the Greek Septuagint Old Testament. We can assume with certainty that John learned how to read the Greek Old Testament. It is not a big stretch at all to believe that John also learned how to write in Greek. It is not absolutely essential that he could write in Greek (although it is very likely that he could), as he could conceivably have used a scribe to write down his thought. Honestly, I really doubt this because the Gospel of John is a very carefully written literary document.
To summarize, the approximately fifty years between the events in Acts 4 and the time of the writing of John and the fact that John ministered to a Greek-speaking church can easily explain how an “unschooled, ordinary man” could write the Book of John in Greek.