First of all you should NOT add anything in folders other than app/code , app/design app/i18n. I think some scripts at magento root might also be acceptable but putting files in bin definitely isn't.
You can create a module for doing just what you asking for thanks to symphony's implementation in magento.
There is an article about making a simple console command here - http://devdocs.magento.com/guides/v2.2/extension-dev-guide/cli-cmds/cli-howto.html
Also here is sample module -
Hope it solved your issue.