Light of the World (τὸ φῶς τοῦ κόσμου) occurs three times in the New Testament. Here:
I am the light of the world. Whoever follows me will not walk in darkness, but will have the light of life. (John 8:12, ESV)
We must work the works of him who sent me while it is day; night is coming, when no one can work. As long as I am in the world, I am the light of the world. (John 9:4–5, ESV)
You are the light of the world. A city set on a hill cannot be hidden. Nor do people light a lamp and put it under a basket, but on a stand, and it gives light to all in the house. In the same way, let your light shine before others, so that they may see your good works and give glory to your Father who is in heaven. (Matt 5:14–16, ESV)
Matt. 5:14 seems like a contradiction to the two passages in John, except John 9:5 has “as long as I am in the world,” opening up an extension in Matt. 5. Note that both Matt. 5:16 and John 9:4 mention good works, and John 4 has “we.” 1 John has a good explanation and clarifies the good works.
This is the message we have heard from him and proclaim to you, that God is light, and in him is no darkness at all. If we say we have fellowship with him while we walk in darkness, we lie and do not practice the truth. But if we walk in the light, as he is in the light, we have fellowship with one another, and the blood of Jesus his Son cleanses us from all sin. If we say we have no sin, we deceive ourselves, and the truth is not in us. If we confess our sins, he is faithful and just to forgive us our sins and to cleanse us from all unrighteousness. If we say we have not sinned, we make him a liar, and his word is not in us. (1 John 1:5–10, ESV)
While the above mentions walking, the next gives more detail about the good works.
... whoever says he abides in him ought to walk in the same way in which he walked. Beloved, I am writing you no new commandment, but an old commandment that you had from the beginning. The old commandment is the word that you have heard. At the same time, it is a new commandment that I am writing to you, which is true in him and in you, because the darkness is passing away and the true light is already shining. Whoever says he is in the light and hates his brother is still in darkness. Whoever loves his brother abides in the light, and in him there is no cause for stumbling. But whoever hates his brother is in the darkness and walks in the darkness, and does not know where he is going, because the darkness has blinded his eyes. (1 John 2:6–11, ESV)
Notice the similar wording to here:
A new commandment I give to you, that you love one another: just as I have loved you, you also are to love one another. By this all people will know that you are my disciples, if you have love for one another.” (John 13:34–35, ESV)
This is my commandment, that you love one another as I have loved you. Greater love has no one than this, that someone lay down his life for his friends. (John 15:12–13, ESV)
This discussion could go on and on, but it is when we show this love to people that our works glorifies God or shows to them who God is. This is the light to walk in.