Great question! I do not know the history of its placement in the selichot (and I'm not familiar with the piyut since I recite the Sephardic selichot).
Regarding its origin, I would guess it comes from Yeshayahu 62:6-7:
עַל-חוֹמֹתַיִךְ יְרוּשָׁלִַם הִפְקַדְתִּי שֹׁמְרִים כָּל-הַיּוֹם וְכָל-הַלַּיְלָה תָּמִיד לֹא יֶחֱשׁוּ הַמַּזְכִּרִים אֶת-יי אַל-דֳּמִי לָכֶם. וְאַל-תִּתְּנוּ דֳמִי לוֹ עַד-יְכוֹנֵן וְעַד-יָשִׂים אֶת-יְרוּשָׁלִַם תְּהִלָּה בָּאָרֶץ
On your walls, O Jerusalem, I have appointed watchmen; all day and all
night, they shall never be silent; those who remind the Lord, be not
silent. / And give Him no rest, until He establishes and until He
makes Jerusalem a praise in the land.
These watchmen, as Rashi explains, are the ministering angels who remind God to rebuild Jerusalem. He's quotes Menachot 87a, which also references pesukim on mercy for Zion. Then he comments on "appointed watchmen" as a reference to being written in a book of remembrances.
In light of the Rashi, it sounds quite appropriate to recite some derivation of it as we approach Rosh Hashanah, if you ask me!
Also, in Yechezkel 16:60, God tells Jerusalem:
וְזָכַרְתִּי אֲנִי אֶת-בְּרִיתִי אוֹתָךְ, בִּימֵי נְעוּרָיִךְ; וַהֲקִימוֹתִי לָךְ, בְּרִית עוֹלָם
But I shall remember My covenant with you in the days of your youth, and I shall establish for you an everlasting covenant.
Then in 60:63:
לְמַעַן תִּזְכְּרִי, וָבֹשְׁתְּ, וְלֹא יִהְיֶה-לָּךְ עוֹד פִּתְחוֹן פֶּה, מִפְּנֵי כְּלִמָּתֵךְ--בְּכַפְּרִי-לָךְ לְכָל-אֲשֶׁר עָשִׂית, נְאֻם אֲדֹנָי יי
In order that you remember and be ashamed, and you will no longer have an excuse by reason of your humiliation, when I forgive you for all that you have done," says the Lord God.
Maybe I shouldn't read too much into B'Chapri, but it did jump out. There are other pesukim on God remembering Jerusalem/Zion, ie., Yeshayahu 49:14-18. Then again, these are just my speculations.