There is a command line tool called mysides, which allows you to List sidebar favorites items, Append a new item to the end of a list, Insert a new item at the start of the list, and Remove the item (by name).
mysides can be installed in Terminal via Homebrew by using the command brew install mysides
After mysides has been installed, the first thing I did was to list of all of my Finder sidebar favorites (removing "-> " from each line of the output) and wrote that to file ~/Desktop/My_Sidebar.txt ... With this following command in Terminal.
/usr/local/bin/mysides list |sed -E 's@-> @@g' > ~/Desktop/My_Sidebar.txt
If "On%20My%20Mac x-finder:OnMyMac" ...appears in the ~/Desktop/My_Sidebar.txt file then remove that line from the file.
The next thing I did was to retrieve only the names of all of my Finder sidebar favorites from the ~/Desktop/My_Sidebar.txt file and saved that output to file ~/Desktop/My_Sidebar_Names.txt ... With this following command in Terminal.
cut -d " " -f 1 ~/Desktop/My_Sidebar.txt > ~/Desktop/My_Sidebar_Names.txt
The file ~/Desktop/My_Sidebar_Names.txt will be the file I use to loop through and remove each item from my Finder sidebar favorites so that next I can go back and restore everything.
This following one line of code in Terminal.app will remove all of Finder sidebar favorites.
cd ~/Desktop ;while read -r line ;do /usr/local/bin/mysides remove "$line" ;done < My_Sidebar_Names.txt 2>&1 >/dev/null
Then, this following one line of code in Terminal.app will restore all of Finder sidebar favorites.
cd ~/Desktop ;while read -r line; do /usr/local/bin/mysides add $line ;done < My_Sidebar.txt 2>&1 >/dev/null
This following animation demonstrates restoring my Finder sidebar favorites after I had removed them all.